const { ccclass, property } = cc._decorator;
import { testData } from "../testData";
import { PoolUtil } from "../../../vv/utils/PoolUtil";
import { resourcePath, EPoolName } from "../../constants";

/**
 * 拍卖行
 */
@ccclass
export default class AuctionHouse extends cc.Component {
    private auctionItemPrefab: cc.Prefab = null;
    private itemLayout: cc.Node = null; //物品布局

    onLoad() {
        // this.itemLayout = 

    }

    public init() {
        let data: Array<any> = testData.getAuctionHouseData();

        cc.resources.load(resourcePath.auctionItemPrefab, cc.Prefab, (err, prefab: any) => {
            this.auctionItemPrefab = prefab;
            PoolUtil.inst.initPool(EPoolName.auctionItemPrefab, prefab, data.length);
            data.map((item) => {
                this.addItem(item);
            });
        });
    }

    public refresh() {
        let data: Array<any> = testData.getAuctionHouseData();

        PoolUtil.inst.more(EPoolName.auctionItemPrefab, data, this.auctionItemPrefab);
        data.map((item) => {
            this.addItem(item);
        });
    }

    private addItem(item) {
        let node = PoolUtil.inst.get(EPoolName.auctionItemPrefab);
        this.itemLayout.addChild(node);
        vv.getScript(node).init(item.id, item.lv, item.title, item.desc, item.count, item.itype);
    }
}
